package cn.zswltech.gruul.common.param;

import cn.zswltech.gruul.common.util.DateUtils;
import cn.zswltech.gruul.common.util.StringUtil;
import cn.zswltech.gruul.common.entity.UserDO;
import cn.zswltech.gruul.common.entity.UserOrgRoleDO;
import lombok.Data;

import java.util.List;

@Data
public class UserParam {

    private Long id;

    private String account;

    private String userName;

    private String enUserName;

    private String pwd;

    private String jobs;

    private String avatar;

    private String expiration;

    private Integer gender;

    private Integer status;

    private String lang;

    private String theme;

    private String layout;

    private Integer simplified;

    private String sign;

    private String phone;

    private String email;

    private Long parentId;

    private List<UserOrgRoleDO> orgRoles;

    public static UserDO genUserDO(UserParam userParam) {
        UserDO userDO = new UserDO();
        userDO.setUserName(userParam.getUserName());
        userDO.setEnUserName(userParam.getEnUserName());
        userDO.setAvatar(userParam.getAvatar());
        userDO.setExpiration(StringUtil.timeMillisStr2Date(userParam.getExpiration()));
        userDO.setGender(userParam.getGender());
        userDO.setStatus(userParam.getStatus());
        userDO.setLang(userParam.getLang());
        userDO.setJobs(userParam.getJobs());
        userDO.setTheme(userParam.getTheme());
        userDO.setLayout(userParam.getLayout());
        userDO.setPhone(userParam.getPhone());
        userDO.setSign(userParam.getSign());
        userDO.setEmail(userParam.getEmail());
        userDO.setSimplified(userParam.getSimplified());
        if (userDO.getExpiration() != null) {
            String dateStr = DateUtils.formatDateYMD(userDO.getExpiration());
            userDO.setExpiration(DateUtils.parseDate(dateStr + " 23:59:59"));
        }
        return userDO;
    }
}